package com.ruoyi.cms.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cms.domain.CmsNavigation;
import com.ruoyi.cms.service.ICmsNavigationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 页面导航Controller
 * 
 * @author ruoyi
 * @date 2024-02-01
 */
@RestController
@RequestMapping("/cms/navigation")
public class CmsNavigationController extends BaseController
{
    @Autowired
    private ICmsNavigationService cmsNavigationService;

    /**
     * 查询页面导航列表
     */
    @PreAuthorize("@ss.hasPermi('cms:navigation:list')")
    @GetMapping("/list")
    public TableDataInfo list(CmsNavigation cmsNavigation)
    {
        startPage();
        List<CmsNavigation> list = cmsNavigationService.selectCmsNavigationList(cmsNavigation);
        return getDataTable(list);
    }

    /**
     * 导出页面导航列表
     */
    @PreAuthorize("@ss.hasPermi('cms:navigation:export')")
    @Log(title = "页面导航", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmsNavigation cmsNavigation)
    {
        List<CmsNavigation> list = cmsNavigationService.selectCmsNavigationList(cmsNavigation);
        ExcelUtil<CmsNavigation> util = new ExcelUtil<CmsNavigation>(CmsNavigation.class);
        util.exportExcel(response, list, "页面导航数据");
    }

    /**
     * 获取页面导航详细信息
     */
    @PreAuthorize("@ss.hasPermi('cms:navigation:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cmsNavigationService.selectCmsNavigationById(id));
    }

    /**
     * 新增页面导航
     */
    @PreAuthorize("@ss.hasPermi('cms:navigation:add')")
    @Log(title = "页面导航", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmsNavigation cmsNavigation)
    {
        return toAjax(cmsNavigationService.insertCmsNavigation(cmsNavigation));
    }

    /**
     * 修改页面导航
     */
    @PreAuthorize("@ss.hasPermi('cms:navigation:edit')")
    @Log(title = "页面导航", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmsNavigation cmsNavigation)
    {
        return toAjax(cmsNavigationService.updateCmsNavigation(cmsNavigation));
    }

    /**
     * 删除页面导航
     */
    @PreAuthorize("@ss.hasPermi('cms:navigation:remove')")
    @Log(title = "页面导航", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cmsNavigationService.deleteCmsNavigationByIds(ids));
    }
}
